
import UIManager from "../../../engine/UIManager";
import ViewBase from "../../../engine/ViewBase";
import { ClubSocketClient } from "../../../net/ClubSocketClient";
import { RoomConfig } from "../../config/RoomConfig";
import RoomConfig_Mj from "../../config/RoomConfig_Mj";
import { ViewConfig } from "../../config/ViewConfig";
import { UserModel } from "../../model/UserModel";
import { UIHelper } from "../../util/UIHelper";

const { ccclass, property } = cc._decorator;

@ccclass
export default class ViewClubCreateTemplate extends ViewBase {

    private roomConfig: RoomConfig_Mj | RoomConfig

    private txtInputName: cc.EditBox;

    public onInitChild(roomConfig: RoomConfig_Mj | RoomConfig) {
        this.roomConfig = roomConfig;
    }

    onEnable(): void {
        super.onEnable();
        this.txtInputName = this.getChild(this.node, "txtInputName", cc.EditBox);
        let btnOK: cc.Node = this.findChild(this.node, "btnOK")
        UIHelper.onAddEvent(btnOK, () => {
            ClubSocketClient.req_club_create_room_template(UserModel.instance.nowClub.clubid, this.txtInputName.string, this.roomConfig, () => {
                UIManager.instance.closeSingleView(ViewConfig.viewConfig.ViewCreateRoom)
                this.closeView()
            })
        })
        let btnCancel: cc.Node = this.findChild(this.node, "btnCancel")
        UIHelper.onAddEvent(btnCancel, () => {
            this.closeView()
        })
    }

}
